<?php
class portada extends controller
{
	private $tpl ;
	public function __construct(tpl & $t)
	{
		$t->set("TITLE","PORTADA");
		$this->tpl = & $t;
	}
	public function __getDefault()
	{
		
	}
	public function inicio()
	{
		$u = MEDIA_BASE_PATH .'/_portada';
		return $this->tpl->parseAndRender("portada/portada",array(
			"fruta" => new LimitIterator(new imagenes_iterator(new DirectoryIterator($u. '/frutas')),0,10),
			"verdura" => new LimitIterator(new imagenes_iterator(new DirectoryIterator($u . '/verduras')),0,10)
		));
	}
}
class imagenes_iterator extends FilterIterator
{
	public function current()
	{
		$nombre = parent::current()->getFileName();
		$ruta_general = strtr(parent::current()->getPathName() ,array(BASE_PATH=>BASE_URL ,'\\'=>'/') );
		$r = pathinfo($ruta_general );
		//$sobra = dirname($r['dirname']);
		return array(
		'url' => $ruta_general,
		'nombre' => $r['filename']
		//,'url_link' => BASE_URL . '/index.php/alimento:alimento' . str_replace($sobra,'',$r['dirname']) .'/'. $r['filename']
		
		);
	}
    public function accept() {
        // Sólo acepta string con una longitud de 10 o mayor
        return parent::current()->isFile()?true:false;
    }

}